Skip to content

fix(tokenizers): add missing tokenize_raw to TokenizerTransformers#2

Open
tatsuru-okada-business wants to merge 1 commit into
softmatcha:mainfrom
tatsuru-okada-business:fix/transformers-tokenize-raw
Open

fix(tokenizers): add missing tokenize_raw to TokenizerTransformers#2
tatsuru-okada-business wants to merge 1 commit into
softmatcha:mainfrom
tatsuru-okada-business:fix/transformers-tokenize-raw

Conversation

@tatsuru-okada-business

Copy link
Copy Markdown

Problem

Building an index with --backend transformers always crashes:

$ softmatcha-index --index /tmp/idx --backend transformers \
    --model tohoku-nlp/bert-base-japanese-v3 corpus.txt
...
  File ".../concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
AttributeError: 'TokenizerTransformers' object has no attribute 'tokenize_raw'

Cause

The index pipeline (src/softmatcha/index/tokenize.py, tokenize_encode_offsets) calls tokenizer.tokenize_raw(). Every tokenizer implements it (mecab, icu, llama, moses) except TokenizerTransformers, so the transformers backend is effectively unusable for indexing.

Fix

Add tokenize_raw mirroring the llama tokenizer's implementation (identical to tokenize on the stripped line). 3 lines, no behavior change for other backends.

Verification

With this patch, softmatcha-index --backend transformers --model tohoku-nlp/bert-base-japanese-v3 builds a complete index (metadata/offset/rough/sa/index.bin) and softmatcha-search returns expected soft matches on a ~2MB Japanese corpus.

🤖 Generated with Claude Code

The index pipeline (index/tokenize.py: tokenize_encode_offsets) calls
tokenizer.tokenize_raw(), which every tokenizer implements (mecab, icu,
llama, moses) except TokenizerTransformers. As a result, building an
index with --backend transformers always crashes:

    softmatcha-index --index /tmp/idx --backend transformers \
        --model tohoku-nlp/bert-base-japanese-v3 corpus.txt
    ...
    AttributeError: 'TokenizerTransformers' object has no attribute 'tokenize_raw'

This mirrors the llama tokenizer's implementation (tokenize_raw ==
tokenize on the stripped line). Verified: index builds successfully and
search returns expected results with tohoku-nlp/bert-base-japanese-v3.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant